<?php

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

require ( "../includes/config.php" );
require ( "../includes/CGI.php" );
require ( "../includes/SQL.php" );

$cgi = new CGI ();
$sql = new SQL ( $DBusername, $DBpassword, $server, $database );

if ( ! $sql->isConnected () )
{
  die ( $DatabaseError );
}

require ( "includes/Auth.php" );
$auth = new Auth ( $cgi, $sql, $admin_table );
$auth->checkAuth ( "index.php" );

require ( "../includes/CSQL.php" );
require ( "resizer.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Editar Imagem</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
<table border="0" cellpadding="1" cellspacing="0" width="100%"> 
<tbody> 
<tr> 
<td bgcolor="#333333"> <?PHP include "header.php"; ?>
<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="100%"> 
<tbody> 
<tr> 
<td colspan="4"> 
<table width="100%" cellpadding="0" cellspacing="0"> 
<tr> 
<td align="left" valign="top" class="leftbg"> <?PHP include "leftmenu.php"; ?></td> 
<td width="100%" valign="top"> 
<h2 align="left"><img src="images/spacer.gif" height="10" width="15" />Editar Imagem </h2> 
<table width="95%" align="center" cellpadding="0" cellspacing="1"> 
<tr> 
<td width="100%"> 
<?
if($cgi->getValue('Submit') == "Click to Update Image")
{
  if($cgi->getValue('oldIMG') == '')
  {
  // newe image and database insert !!
  }
  else
  {
  // chnage existing image to new photo
   error_log ( "Checking propertyphoto" );
        
    if ( ! isset ( $_FILES ["propertyphoto"] ) || 
         ! is_uploaded_file ( $_FILES ["propertyphoto"] [ 'tmp_name' ] ) )
    {
      error_log ( "Breaking, no uploaded file?" );
      
      print "<br><p align=\"center\"><strong>No Image Uploaded</strong></p>";
    }

    error_log ( "\$_FILES ['propertyphoto'] [ \"error\" ] = " . $_FILES ["propertyphoto"] [ "error" ] . " (UPLOAD_ERR_OK = " . UPLOAD_ERR_OK . ")" );
    
    if ( $_FILES ["propertyphoto"] [ "error" ] == UPLOAD_ERR_OK )
    {
      $tmp_name = $_FILES ["propertyphoto"] [ "tmp_name" ];
	  
	  
      $propertyphotos = $cgi->getValue('oldIMG');
      
      ResizeConserveAspectRatio($tmp_name, $ImagePath . "/" . $propertyphotos, $max_image_resize_width); 
    }
  }
?>

<p align="center"><font color="#CC0000">Imagem atualizada</font></p>
<br />
<form method="post" action="property_edit.php">
<input name="op" type="hidden" value="editestablishment" />
<input name="id" type="hidden" value="<?php echo $cgi->getValue('propid'); ?>" />
<p align="center">
<input value="Ver detalhes" type="submit" class="textinput" />
</p>
</form>
<?
}
else
{
?>
<p><img src="<? echo "$ImageURL/$_POST[propertyphoto]"; ?>" border="0" /></p>
<form method="post" enctype="multipart/form-data">
<input type="hidden" name="oldIMG" value="<? echo $cgi->getValue('propertyphoto'); ?>" />
<input name="propid" type="hidden" value="<?php echo $cgi->getValue('propid'); ?>" />
<input name="propertyphoto" type="file" size="35" />
<input name="propertyref" type="hidden" value="<?php echo $cgi->getValue('propertyref'); ?>" /><br />

<input type="submit" value="Clique para atualizar imagem" name="Submit" />
<?
}
?>
</form></td> 
</tr> 
</table><br /><br /></td>
</tr> 
</table> </td> 
</tr> 
</tbody> 
</table> </td> 
</tr> 
</tbody> 
</table> <?PHP include "footer.php"; ?>
</body>
</html>
